import javax.print.DocFlavor;
import javax.swing.*;
import javax.swing.text.html.HTMLEditorKit;
import java.lang.reflect.Field;
import java.util.*;

enum t{
    A(10) , B(20);
    private int a;
    t(int a) {
        this.a = a;
    }

//    t(char c) {
//
//    }

    public  int getVAl() {
        return a;
    }
}
class MyListNode {

    public ListNode head;

    class ListNode {
        int val;
        ListNode next;

        public ListNode(int val) {
            this.val = val;
        }
    }

    //
    public void text() {
        ListNode node = new ListNode(2);
    }


    public static void main(String[] args) {
        MyListNode my = new MyListNode();
        ListNode h = new ListNode(2);
    }

}
    class ListNode {
  int val;
  ListNode next;
  ListNode() {}
  ListNode(int val) { this.val = val; }
  ListNode(int val, ListNode next) { this.val = val; this.next = next; }
  }
class up implements Comparator<Integer> {

    @Override
    public int compare(Integer o1, Integer o2) {
        return o1-o2;
    }
}

class Inc {
//ok 干完over
    public static void main(String[] args) {
    }

    public boolean isValid (String s) {
        Stack<Character> stack = new Stack<>();
        int i = 0;
        while (i < s.length()) {//碰到左括号就push右括号就就和栈顶的右括号比较，相同就退出，不同就错误
            if (s.charAt(i) == '(' || s.charAt(i) == '[' || s.charAt(i) == '{') {
                stack.push(s.charAt(i));
            }else{//是又括号
                if (stack.isEmpty()) {
                    return false;
                }
                if (stack.peek() == '(' && s.charAt(i) == ')' || stack.peek() == '[' && s.charAt(i) == ']' || stack.peek() == '{' && s.charAt(i) == '}') {
                    stack.pop();
                }else {
                    return false;
                }
            }
            i++;
        }
        if (!stack.isEmpty()) {
            return false;
        }
        return true;

    }
    public int[] nextGreaterElement(int[] nums1, int[] nums2) {
        int[] ant = new int[nums1.length];
        int index = 0;
        for (int i = 0; i < nums1.length; i++) {//遍历num1中的元素
            boolean flg = true;
            int j = 0;
            for (; j < nums2.length; j++) {//找到nums2中等于nums1的数
                if (nums1[i] == nums2[j]) {
                    flg = false;
                    break;
                }
            }
            if (flg) {//如果能进去那么就是不存在
                ant[index++] = -1;
            } else {//存在那么在 后面找到比这个树大的，如果没有，那么就是不存在
                int val = nums2[j];
                for (int k = j; k < nums2.length; k++) {
                    int max = nums2[k];
                    if (max > val) {
                        val = max;
                        break;
                    }
                }
                if (val != nums2[j]) {//存在比他大的
                    ant[index++] = val;
                } else {//不存在
                    ant[index++] = -1;
                }
            }
        }
        return ant;
    }
    public static void main7(String[] args) {
        creatList();
        reverseList(head);
//        ListNode tmp = deleteDuplication(head);
//        oddEvenList(head);
        //
        int[] arr = {1,3};
        List<String> list = buildArray(arr, 3);
    }

    public static List<String> buildArray(int[] target, int n) {
        int[] list = new int[n];
        for (int i = 1; i <= n; i++) {
            list[i - 1] = i;
        }

        List<String> ret = new LinkedList<>();
        int index = 0;//遍历target

        for (int i = 0; i < list.length; i++) {//遍历target
            ret.add("push");//每个都要push
            if (target[index++] != list[i]) {
                ret.add("pop");//这个数字不在target
                index--;//还要在这个为值继续判断是否普存在
            }
            if (index >= target.length) {
                break;
            }
        }
        return ret;
    }
    public static ListNode reverseList(ListNode head) {
        //使用栈
        Stack<ListNode> stack = new Stack<>();
        ListNode cur = head;
        while (cur != null) {
            stack.add(cur);
            cur = cur.next;
        }
        ListNode newHead = new ListNode(-1);
        ListNode curN = newHead;
        while (!stack.isEmpty()) {
            curN.next = stack.pop();
            curN = curN.next;
        }
        curN.next = null;//切断和之前节点的联系
        return newHead.next;


    }
    public static ListNode deleteDuplication(ListNode pHead) {
        Set<Integer> set = new HashSet<>();
        ListNode cur = pHead;
        while (cur != null) {
            if (set.contains(cur.val)) {//存在就删除 但是set中储存的并没哟删除
                pHead = del(pHead, cur.val);//一次就会把所有相同的给删除
            } else {
                set.add(cur.val);
            }
            cur = cur.next;
        }
        return pHead;
    }

    public static ListNode del(ListNode node, int val) {
        ListNode cur = node;
        ListNode prev = node;
        while (cur != null) {
            if (cur == node && cur.val == val) {
                cur = cur.next;
                prev = node = cur;
            } else if (cur.val == val) {//删除
                prev.next = cur.next;
                cur = cur.next;
            } else {
                prev = cur;
                cur = cur.next;
            }
        }
        return node;
    }
    public ListNode oddEvenListbetter(ListNode head) {
        if(head==null){
            return head;
        }
        ListNode evenhead=head.next;
        ListNode odd=head,even=evenhead;
        while(even!=null&&even.next!=null){//不用开辟新空间
            odd.next=even.next;
            odd=odd.next;
            even.next=odd.next;
            even=even.next;
        }
        odd.next=evenhead;
        return head;
    }
    public static ListNode oddEvenList(ListNode head) {
        int index = 1;
        //奇数节点
        ListNode oddNodeHead = null;
        ListNode oddNode = null;
        //偶数节点
        ListNode evenNodeHead = null;
        ListNode evenNode = null;
        for (ListNode cur = head; cur != null; cur = cur.next) {
            ListNode tmpNode = new ListNode(cur.val);
            if (index % 2 == 1) {//为奇数
                if (oddNodeHead == null) {
                    oddNodeHead = tmpNode;
                    oddNode = oddNodeHead;
                } else {
                    oddNode.next = tmpNode;
                    oddNode = oddNode.next;
                }
            } else {//为偶数
                if (evenNodeHead == null) {
                    evenNodeHead = tmpNode;
                    evenNode = evenNodeHead;
                } else {
                    evenNode.next = tmpNode;
                    evenNode = evenNode.next;
                }
            }
            index++;
        }
        oddNode.next = evenNodeHead;
        return oddNodeHead;
    }
    public static void main2(String[] args) {
//        System.out.println(CheckPermutation("abc", "bac"));
//        List<Integer> arr = new ArrayList<>();
    }

    public static void main4(String[] args) {
       String[] words = {"pxlqovnbsgvqjzpfeidchzrodnbqfrccfydzjptukscjuatlsrcurepllxzyghhdepitqptlmfkhzxjgswaulxkfydhkilg","uqklvqnlhdkwryjawkqfajfpbcnhglxlwxlaskxlytr","jvgkxcdkxrvfahjkvhmfuyjzxtyxrsogbtsjybeaxugqymcr","rgxditmosplnqvodtis","jm","ruqjwejuanjtiizcmbieobesnjnadzqvqumggblzmkxilgfarnxwpcawtkzxlvugibpidvwtikloeziuxqoi","wxeyzrnbhlhwxecrgejsrawyulynvgtszwqqlihkcvckgcgtgpyqtkuwvjywmhpskaiwmpyarftqhnogxpith","vdpbykqlihtpvfnqbrcjpggojqbalerohyitktuikbffvfatcnneuvbanjihiaorrjcdthntnrxebfhvshmpodmzhtwnasbm","wgjstkoaojcesfdrllugmojwdmgeejyiqvshlowtktddattunarnohgvqsoskfmbrami","ecwqxbawirvnxvsjybbebclaturorlcbpf","gtjbaigvufrotlwfoqqolnjabnvtbcygtfcytinzpcjbvprdkdjawrcbthmxjrabimhhs","cvzlbrvppkyxtjxzeglzwoagmpjnfxddbwolxmwdohgtfktgftzzkwpianslkpldyfzubtjczse","neaw","mxhmvkajofnmdiiduactlemcvpztscmsnrdhuhquxnnzywsrzxyplgbppiypxwcfbsnyzblaeifo","krekecabfpufucjhqphjnibaeqdvdpmrfougdwugvoioqangdnxromwlxnfeydaneyazzclscqgdxlhhgnoqmslfflzqv","klutvchxsceihfmzitgqakytesfjykribjhjzdruuoycjkwaghmmqkfrhkrtawudtjyjwqbyspamlegqjlwlj","raykfkflqdzrpthdejetwolgciygwaktulkxemkdbbllkjxhnnafsms","os","xhchkcetmlprcdmrnalvkvgabxxnomphqpqhnddqhecogspbdebeoshvjgzvmqu","jqtdysnpskktynxwmsfaabglagnqcllptvuyyqjwrmqaftenusmsahhhqubkwxltpr","sulmwluiwvlroldpiyecaicwrawzwflokefqkdwmxejaovvpbflfdtviinbvvtlhhhefmgfsqs","sxyhcckvyl","vsaacsybcddxvuzkddjmuivsvtjyanpbydmkcwnkmxvsiantgkvkmqjysclsvd","sxcghypulvmfqfunxj","pozekufhlooosxpcggbi","xzaoxzllcixfqbupqozmzrnugj","j","tgslwp","ntrdkixexajlpjgmcbrqimwtqnzfrqjszeiuvrgzclerzmsnagzaxbredvlrmipzflrzusclckmxphc","ifdflsywdfizpodsehrrifsvejcxarrxmxyjgbbvqyqvywncphzfmnxhybxpdcozfnzablfx","uluhplzrsaehaqxfnbcmixueedevhirbwqdyztwaxnkogcauymxgcpabxekib","agtfkinbdccoemxetbryzpluzlpyzicnfopphrxriqm","pdympxpwvxwcqaxrvbvyqkrresrjgzgxuyfxtkgldtathokdbyfsqfmitmiyagtqgijaiazvsumeyutbbwxqdshquzrehn","rqe","sljsvenhhstnnngzqyo","dezrzpgldeimxfoqajuhjctgvalwkhkjemjaxumxqmifglbizusuqlttxirpbqbuvauwy","dkwpyezbmkcskoxxcgrxcewknqgdckjxfyzcmzqcbyeucxbqybxoldogtkmdknsrruvnlfqnpfx","sjeftmjkuperfynbreycwhuoyqybticswblbrrpugzhlrmiedjqufnehevzqwtaebwvdswsz","lolnfyliloqmhjmhhohdtgfajjfdjqpubslbsrwitbjmrcegdrdjzvonxaefdvdfcbqmaaks","qhcoaiocjhuzywkirlblajgeapzajqsoa","sxrmoqxqbtakuqwmrrkljmegbwbeqbywmlyuprwyhljzejbybxoumidpxdrohwdjoqycpxcmivaulnqzneydwqfsvcxgyyseuk","yrowy","dohrzkrzdjehpctnjrvhzojullsiucrhphshwxwicyzkvzbqrztic","rmshnxtbhsdgkiijrmwulocdzjzpgfyimkjdthuzkhoqgkeawgwincubrloknocxwzgqqcxafksxgzh","aymovnuhptozhkiyowbeguzlkmrwjnujgjbdne","abc","vxoigovwmqizmkwbkktqk","uokwktdempzloaglvvkqstztmwzcmhgxtoua","bzwjxqueazlzfojrkbqmhtwrvuwsnfcnylurnddpektekca","qgndjgvzcyajhgmrrnhdywwdbmkhtthwcfiueuxfldanyrmccwcy"};
        String word = "figspbov";
        System.out.println(countCharacters(words, word));

    }

    public static ListNode head;

    private static void push(int val) {
        if (head == null) {
            head = new ListNode(val);
            return;
        }
        ListNode tmp = head;
        while (tmp.next != null) {
            tmp = tmp.next;
        }
        tmp.next = new ListNode(val);
    }

    static void creatList() {
        for (int i = 0; i < 5; i++) {
            push(i);
        }
//        push(1);
//        push(1);
//        push(2);
//        push(3);
//        push(3);
//        push(4);
////        push(4);
//        push(5);
//        push(5);
//        for (int i = 1; i <= 3; i++) {
//            push(i);
//        }
//        for (int i = 3; i > 0; i--) {
//            push(i);
//        }
//        push(5);
//        push(-3);
//        push(-4);
//        push(1);
//        push(6);
//        push(-2);
//        push(-5);
//        push(1);
//        push(2);
//        push(3);
//        push(4);
//        push(5);
    }
    public static void main5(String[] args) {
        String date = "2004-03-01";
        Set<Integer> map = new TreeSet<>();
//        System.out.println(dayOfYear(date));
        creatList();
        System.out.println(head.val);
//        Collections.reverse();
//        List<Integer> tmp;
        ListNode a = new ListNode();
        removeDuplicateNodes(head);

    }

    public static void main6(String[] args) {
//        creatList();
        push(1);
        push(2);
        push(3);
        ListNode tmp = head;
        while (tmp != null) {
            tmp = tmp.next;
        }
        tmp = new ListNode(5);

    }
    //看不懂很神奇
    public ListNode sortListNB(ListNode head) {
        if(head == null || head.next == null )return head;
        int max = Integer.MIN_VALUE;
        int min = Integer.MAX_VALUE;
        ListNode cur = head;
        while(cur !=null){
            max = Math.max(max,cur.val);
            min = Math.min(min,cur.val);
            cur = cur.next;
        }

        int n = max-min+1;
        int[] temp = new int[n];
        cur = head;
        while(cur!=null){
            temp[cur.val - min]++;
            cur = cur.next;
        }

        cur = head;
        for(int i=0;i<n;i++){
            while(temp[i]!=0){
                cur.val = i+min;
                temp[i]--;
                cur = cur.next;
            }
        }
        return head;

    }
    public ListNode sortList(ListNode head) {
        int size = 0;
        int[] arr = new int[size];
        ListNode tmp = head;
        while (tmp != null) {//将链表变为数组
            if (size == arr.length) {
                arr = Arrays.copyOf(arr, arr.length * 2);
            }
            arr[size++] = tmp.val;
            tmp = tmp.next;
        }
        arr = Arrays.copyOf(arr, size);
        MySort.shellSort(arr);
        //吧拍好序的数组变为链表
        ListNode node = head;
        Boolean once = true;
        for (int val : arr) {
            if (once) {
                node = new ListNode(val);
                head = node;
                once = false;
            } else {
                node.next = new ListNode(val);
                node = node.next;
            }
        }
        return head;
    }
    public ListNode sortList1(ListNode head) {
        List<Integer> list = new LinkedList<>();
        ListNode tmp = head;
        while (tmp != null) {
            list.add(tmp.val);
            tmp = tmp.next;
        }
        list.sort(new up());
        Boolean once = true;
        ListNode cur = null;
        for (int i = 0; i < list.size(); i++) {
            if (once) {
                head = new ListNode(list.get(i));
                cur = head;
                once = false;
            } else {
                cur.next = new ListNode(list.get(i));
                cur = cur.next;
            }
        }
        return head;
    }

    public ListNode addTwoNumbersBetter(ListNode l1, ListNode l2) {
        ListNode pre = new ListNode();
        ListNode cur = pre;
        int carry = 0;
        while(l1 != null || l2 != null) {
            int x = l1 == null ? 0:l1.val;
            int y = l2 == null ? 0:l2.val;
            int sum = x+y+carry;
            carry = sum/10;
            sum = sum%10;
            cur.next = new ListNode(sum);
            cur = cur.next;
            if(l1 != null) {
                l1 = l1.next;
            }
            if(l2 != null) {
                l2 = l2.next;
            }
        }
        if(carry ==1) {
            cur.next = new ListNode(carry);
        }
        return pre.next;
    }
    public ListNode addTwoNumbers(ListNode l1, ListNode l2) {
        boolean fla = false;//控制进位
        ListNode cur1 = l1;
        ListNode cur2 = l2;
        ListNode prev = l1;
        for (cur1 = l1, cur2 = l2;//会有一边为空一边不为空的情况
             cur1 != null && cur2 != null; cur1 = cur1.next, cur2 = cur2.next) {
            int tmpVal = cur1.val + cur2.val;
            if (fla) {//大于10，那么下一位要进1
                tmpVal++;
                fla = false;
            }
            if (tmpVal >= 10) {//大于10进位
                fla = true;
            }
            cur1.val = tmpVal % 10;
            prev = cur1;
        }
        if (cur2 != null) {//这时的cur1指向了空将剩下的cur2连在cur1最后,并判断fla
            prev.next = cur2;
            for (; cur2 != null; cur2 = cur2.next) {
                int tmp = cur2.val;//有可能原本九尾0
                if (fla) {
                    cur2.val=(tmp+1)%10;
                    tmp++;
                    fla = false;
                }
                if (tmp == 10) {//为0进位
                    fla = true;
                }
                prev = cur2;
            }
        }

        if (cur1 != null) {
            for (; cur1 != null; cur1 = cur1.next) {
                int tmp = cur1.val;//有可能原本九尾0
                if (fla) {
                    cur1.val=(tmp+1)%10;
                    tmp++;
                    fla = false;
                }
                if (tmp == 10) {//为0进位
                    fla = true;
                }
                prev = cur1;
            }
        }
        System.out.println(cur1);
        System.out.println(fla);
        if (fla) {//若这是还要进位，那么就new节点
            prev.next = new ListNode(1);
        }
        return l1;
    }

    public static ListNode removeZeroSumSublists(ListNode head) {
        ListNode pHead = new ListNode(0);
        pHead.next = head;
        Map<Integer, ListNode> map = new HashMap<>();
        int preSum = 0;
        for (ListNode node = pHead; node != null; node = node.next) {
            preSum += node.val;
            map.put(preSum, node);
        }
        preSum = 0;
        for (ListNode node = pHead; node != null; node = node.next) {
            //有俩个相同的preSum(k)说明在俩这个k之间的节点的值相加为0,将前一个节点和后一个节点的next连上
            preSum += node.val;
            node.next = map.get(preSum).next;
        }
        return pHead.next;
    }
    public static ListNode removeZeroSumSublists1(ListNode head) {
        int sum = 0;
        int nagativeSun = 0;
        int size = 0;//数组中的元素
        int[] arr = new int[10];
        ListNode tmp = head;
//        PriorityQueue<Integer> stack = new PriorityQueue<>((a,b)->b-a);//默认建立小根堆 会去重
        while (tmp != null) {
            int tmpVal = tmp.val;
            sum += tmpVal;
            if (size == arr.length) {
                arr = Arrays.copyOf(arr, (size * 3)/2);
            }
            if (tmpVal > 0) {
                arr[size++] = tmpVal;
            } else {
            nagativeSun += tmpVal;
            }
            tmp = tmp.next;
        }

        if (size == 1 && arr[size] == sum) {
            return new ListNode(arr[size]);
        } else if (size == 1) {
            return null;
        }

        for (int i = 0; i < size - 1; i++) {
            ListNode tmpHead = new ListNode(arr[i]);
            head = tmpHead;
            int tmpSun = sum;
            int tmpNagative = nagativeSun;
            tmpSun -= arr[i];
            for (int j = i + 1; j < size; j++) {//每次循环一次就是对剩下的进行一次排列
                if (tmpSun - arr[j] >= 0) {//说明这些值加进去还是不够
                    tmpSun -= arr[j];
                    tmpHead.next = new ListNode(arr[j]);
                    tmpHead = tmpHead.next;
                }else {//将不会插入最终数组的值去和负数的最终值相比 因为负数和正数相加为0的值不能插入最终数组
                    tmpNagative += arr[j];
                }
                if (tmpSun == 0 && tmpNagative ==0 ) {//说明剩下的值刚刚凑成sum
                    return head;
                }
            }
        }
        return null;
    }
    public static ListNode removeDuplicateNodes(ListNode head) {
        if(head == null){
            return null;
        } Set<Integer> map = new HashSet<>();
        ListNode prev = head;
        ListNode cur = head.next;
        map.add(head.val);
        while (cur != null) {
            if (!map.contains(cur.val)) {
                prev.next = cur;
                map.add(cur.val);
                prev = cur;
            }
            cur = cur.next;
        }
        prev.next = null;
        return head;
    }
    public int[] reverseBookList(ListNode head) {
        List<Integer> list = new ArrayList<>();
        while(head != null){
            list.add(head.val);
            head = head.next;

        }
        Collections.reverse(list);//需要是list类或其子类，反正自己写的不认
//        Integer[] arr = Arrays.copyOfRange(list.toArray(), 0, list.size(), Integer[].class);
//        int[] ed = new int[arr.length];
        int[] ed = new int[list.size()];
//        int i = 0;
//        while (list.size() != 0) {
//            ed[i++] = list.get(0);
//            list.remove(0);
////        }
//        for (int i = 0; i < arr.length; i++) {
//            ed[i] = arr[i];
//        }
        for (int i = 0; i < list.size(); i++) {
            ed[i] = list.get(i);
        }
        return ed;
    }

    public static int dayOfYear(String date) {
        int[] leapYear = {0,31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
        int[] Year = {0,31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
        StringBuffer year = new StringBuffer(date.substring(0,4));
        StringBuffer month = new StringBuffer(date.substring(5,7));
        StringBuffer day = new StringBuffer(date.substring(8));
        int countDay = 0;
//        String s = year.toString();
//        int text = ;
        if (isLeapYear(Integer.parseInt( year.toString()))) {
            //是闰年
            for (int i = 1; i < Integer.parseInt(month.toString()); i++) {
                countDay += leapYear[i];
            }
            countDay += Integer.parseInt(day.toString());
        } else {
            //是平年
            for (int i = 1; i < Integer.parseInt(month.toString()); i++) {
                countDay += Year[i];
            }
            countDay += Integer.parseInt(day.toString());
        }
        return countDay;
    }

    private static boolean isLeapYear(int year) {
        if ((0 == year % 4 && year % 100 != 0) || (0 == year % 400)) {
            return true;
        }else{
            return false;
        }
    }
    public static int countCharacters(String[] words, String chars) {
        Map<Character, Integer> map = new HashMap<>();
        for (int i = 0; i < chars.length(); i++) {
            if (map.containsKey(chars.charAt(i))) {
                map.put(chars.charAt(i), map.get(chars.charAt(i)) + 1);
            } else {
                map.put(chars.charAt(i), 1);
            }
        }
        int charCount = 0;
        for(int i = 0;i < words.length;i++){//遍历数组
            boolean flg = true;
            Map<Character, Integer> tmp = new HashMap<>(map);
            for(int j = 0; j < words[i].length();j++){//遍历字符串

                if (tmp.containsKey(words[i].charAt(j)) && tmp.get(words[i].charAt(j)) > 0) {//存在这个字符次数且不为0
                    tmp.put(words[i].charAt(j), tmp.get(words[i].charAt(j)) - 1);
                } else {
                    flg = false;
                    break;
                }
            }
            if(flg){
                charCount+=words[i].length();
            }
        }
        return charCount;
    }
    public static void main3(String[] args) {
        int[] arr ={3,7,2};
        System.out.println(lastStoneWeight(arr));
        String s = new String("aaabb");
        Set<Character> set = new HashSet<>();
        set.add('a');
//        set.contains()

    }
    public static int lastStoneWeight(int[] stones) {
        PriorityQueue<Integer> stone = new PriorityQueue<>((a, b) -> b-a);//大根堆
        for (int a : stones) {
            stone.offer(a);
        }
        while (stone.size() > 1) {
            int max = stone.remove();
            int maxL = stone.remove();

            stone.offer(Math.abs(max - maxL));
        }
        return stone.poll();
    }
    public static int lastStoneWeight1(int[] stones) {
        List<Integer> stone = new ArrayList<>();
        for (int i = 0; i < stones.length; i++) {
            stone.add(stones[i]);
        }
        while (stone.size() > 1) {
            stone.sort(new up());
            int max = stone.get(stone.size() - 1);
            int maxL = stone.get(stone.size() - 2);

            stone.remove(stone.size() - 1);
            stone.remove(stone.size() - 1);

            stone.add(0,max - maxL);
        }
        return stone.get(0);
    }
    public static boolean CheckPermutation(String s1, String s2) {
        if(s1.length() != s2.length()){
            return false;
        }
        StringBuffer ss1 = new StringBuffer(s1);
        StringBuffer ss2 = new StringBuffer(s2);

        for(int i = 0;i<ss2.length();i++){
            int indexSS1 = ss1.indexOf(s2.charAt(i)+"");
            if (indexSS1 < 0) {
                return false;
            }
            //删除这个下表的值
            ss1.delete(indexSS1,indexSS1+1);
        }
        if(ss1.length()==0){
            return true;
        }
        return false;
    }
    static int aa;
    public static void main11(String[] args) {
//        this.aa++;
//        int a[] = new int[9];
        StringBuffer s = new StringBuffer("aaa");
        StringBuffer s1 = new StringBuffer("");
        System.out.println("---");
        System.out.println(s1);
        System.out.println(s1.length());
        System.out.println(s1.equals(""));
        System.out.println("---");
        System.out.println(s.toString());
//        s.delete(0, 1);//包前不包后
        s.delete(2,3);
        System.out.println(s.indexOf("a"));
        System.out.println(s.toString());
//        Inc inc = new Inc();
//        int i = 0;
//        i = i++;
//        i++;
//        System.out.println(i++);//0
//        System.out.println(i++);//1
//        inc.fermin(i);
//        i = ~++i;
//        System.out.println(i);
    }

    void fermin(int i) {
        i++;
    }
}
enum romanNum {
    I(1), V(5), X(10), L(50), C(100), D(500), M(1000);
    private int num;

    romanNum(int num) {
        this.num = num;
    }

    public int getNum() {
        return num;
    }
}
public class text {
    public static int romanToInt(String s) {
        int count = 0;
        for (int i = 0; i < s.length(); i++) {
            if (i+1<s.length() && s.charAt(i) == 'I' && s.charAt(i + 1) == 'V') {
                count += 4;
                i++;
                continue;
            } else if (i + 1 < s.length() && s.charAt(i) == 'I' && s.charAt(i + 1) == 'X') {
                count += 9;
                i++;
                continue;
            } else if (i + 1 < s.length() && s.charAt(i) == 'X' && s.charAt(i + 1) == 'L') {
                count += 40;
                i++;
                continue;
            } else if (i + 1 < s.length() && s.charAt(i) == 'X' && s.charAt(i + 1) == 'C') {
                count += 90;
                i++;
                continue;
            } else if (i + 1 < s.length() && s.charAt(i) == 'C' && s.charAt(i + 1) == 'D') {
                count += 400;
                i++;
                continue;
            } else if (i + 1 < s.length() && s.charAt(i) == 'C' && s.charAt(i + 1) == 'M') {
                count += 900;
                i++;
                continue;
            }
            count += romanNum.valueOf(String.valueOf(s.charAt(i))).getNum();
        }
        return count;
    }


    //    实现函数 int sqrt(int x).

    public static void maiwn(String[] args) {
        String a = "V";
        String aa = "MCMXCIV";
        System.out.println(romanToInt(a));
        Double d = 1.0;

//        switch(d) {//不能是小数，其他的都可以

//        }
//        System.out.println(t.valueOf('A').getVAl());
//        System.out.println(t.values());
//        System.out.println(t.valueOf("A").getVAl());
//        System.out.println(t.A.getVAl());
        System.out.println(isHappy(19));
    }
    public int addDigits(int num) {
        int num1 = 0;
        while(true){
            //获得每一位相加
            while(num != 0){
                num1 += num%10;
                num/=10;
            }
            if(num1 /10 == 0){
                return num1;
            }
            num = num1;
            num1 = 0;
        }
    }

    public int guessNumber(int n) {
        long left = 1;
        long right = n;
        while(true){
            long middle =( left+right)/2;
            if(guess((int)middle)>0){//小了
                left = middle+1;
            }else if(guess((int)middle)<0){//大了
                right = middle-1;
            }else{
                return (int)middle;
            }
        }
    }

    private int guess(int middle) {
        return 0;
    }

    public float doS() {
//        int i = 0;
//        double i = 0;//不能高精度到低精度 可以第精度到高精度
        long i= 0;
        return i;
    }

    public static boolean isHappy(int n) {
        int num = 0;
        int tmp = n;
        for (int i = 0; i < 50; i++) {
            //获得每一位
            while (tmp != 0) {
                int tmp1 = tmp % 10;
                num += tmp1 * tmp1;
                tmp /= 10;
            }
            if (num == 1) {
                return true;
            }
            tmp = num;
            num = 0;
        }
        return false;
    }
    public static int sqrt(int x) {
        long left = 1;
        long right = x;
        while (true) {
            long middle = (left + right) / 2;
            if (middle * middle > x) {
                right = middle;
            } else if (middle * middle == x || middle == left) {
                return (int)middle;
            } else if ((middle * middle) < x) {
                left = middle;
            }
        }
    }
    public static int removeDuplicates(int[] nums) {
        int k = 0;
        for(int i = 0; i < nums.length;i++){
            if(nums[i] != nums[k]){
                k++;
                nums[k] = nums[i];
            }
        }
        return k+1;
    }
    public int removeElement(int[] nums, int val) {
        int left = 0;
        for(; left < nums.length;left++){
            if(nums[left]==val){
                int i = left;
                for(;i < nums.length;i++){//从后找到一个不同的和他交换
                    if(nums[i] != val){
                        break;
                    }
                }
                if(i == nums.length){//后面全是相同的数字
                    return left;
                }
                //交换
                int tmp = nums[left];
                nums[left] = nums[i];
                nums[i] = tmp;
            }
        }
        return left;
    } public static void m1ain(String[] args) {
        int[] a;
        byte d = 3;
        byte c = 4;
//        d = c + d;//相加后会提升为int类型
        d += c;//+-会根据变量类型进行类型转换
//        a.length;
//        Arrays.sort(a);
        Math.log(1);
//        Float a = 1.0F;
        System.out.println(sqrt(909520789));
        System.out.println(Math.sqrt(909520789));
        int b = -2;
//        int c;
        ++b;
//        a = ++(b++);
        StringBuffer s = new StringBuffer();
//        s.append();
        s.toString();
    }
    public String truncateSentence(String s, int k) {
        StringBuffer s1 = new StringBuffer();
        for(int i = 0; i < s.length();i++){
            if(s.charAt(i) == ' '){
                k--;
            }if(k == 0){
                break;
            }
            s1.append(s.charAt(i));
        }
        return s1.toString();
    }
    public String truncateSentence1(String s, int k) {
        int i = 0;
        for (; i < s.length(); i++) {
            if (s.charAt(i) == ' ') {
                k--;
            }
            if (k == 0 ) {
                return s.substring(0,i);
            }
        }
        return  s.substring(0,i);
    }
}

